# -*- coding: utf-8 -*-
'''
@author: Hugo
@file: pyppeteer.py
@time: 2021/8/6 18:57
'''
import pyppeteer
import requests
from pyppeteer import launch
import asyncio
import time
from pyquery import PyQuery as pq
from utils.base import FakChromeUA,Spider
async def main(): # 启动一个浏览器
    browser = await launch(headless=False,args=['--disable-infobars','--window- size=1920,1080']) # 创建一个页面
    page = await browser.newPage()
    # await page.setViewport({'width': 1200, 'height': 800})
    # 伪装
    await page.evaluateOnNewDocument('() =>{ Object.defineProperties(navigator,''{ webdriver:{ get: () => false } })}')
    time.sleep(1)
    await page.setUserAgent(
        "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.36 Safari/536.5")

    await page.goto('https://www.zhipin.com/c100010000-p130109/?ka=search_130109')
    time.sleep(3)
    #  从触发JS
    dimensions = await page.evaluate('''() => { return { cookie: window.document.cookie, } }''')
    # time.sleep(3)
    print(dimensions, type(dimensions))
    await page.waitForXPath('//span[@class="job-name"]')
    data =pq(await page.content())
    print(data.text())

# asyncio.get_event_loop().run_until_complete(main())


async def feifei():
    browser = await pyppeteer.launch(headless=False)
    page = await browser.newPage()
    await page.goto('https://pic.netbian.com/4kmeinv/')
    # time.sleep(3)
    ele = await page.JJ('.clearfix li a img')
    for i in ele:
        src = await(await i.getProperty('src')).jsonValue()
        print(src)
asyncio.get_event_loop().run_until_complete(feifei())